<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Models\DeepNew;
use App\Models\News;
use Carbon\Carbon;
use App\Jobs\TranslateNewsJob;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Http;

class AutoExamineDeepNews extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'cc:auto-examine-deep-news';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {

     /*   $header=[
            "x-cb-apikey"=>"6a8e204fac2d41b3a79f224ccf542880",
            "x-cb-host"=> "www.istockphoto.com",
            "accept"=>"application/json"
        ];
        $response = Http::withHeaders($header)->get('https://api.cloudbypass.com/search/2/image-film', [
                'istockcollection' => '',
                'phrase' => 'alibaba',
            ]);*/
       /*$headers = [
            'accept' => 'application/json',
            'user-agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36',
            "Content-Type"=>"application/json"
        ];
        $response = Http::withHeaders($headers)
                  ->post('http://8.219.124.70:8191/v1', [
                'istockcollection' => '',
                'phrase' => 'alibaba',
                'url'=>"https://www.istockphoto.com/search/2/image-film",
                "cmd"=>"request.get",
            ]);

        dd($response);
        if ($response->successful()) {
            $dds = $response->json();
            
            dd($dds);
        } else {
            // 错误处理
        }

        dd(1);*/
        // dispatch(new TranslateNewsJob($new))->onQueue('news');
        $Deepnews = DeepNew::query()
                        ->where('created_at',">",Carbon::yesterday())
                        ->whereNull('content_zn')
                        ->where("is_examine",false)
                        ->select(DB::raw('*, (likes + collections) as total'))
                        ->orderbyDesc('total')->take(50)->get();
        

        foreach($Deepnews as $new){
           // dispatch(new TranslateNewsJob($new))->onQueue('news');
        }


        $news = News::query()->where('created_at',">",Carbon::today())->whereNull('content_zn')->where("is_examine",false)->get();
        
        foreach($news as $new){

            //dispatch(new TranslateNewsJob($new))->onQueue('news');
        }

    }
}
